package com.blog.util;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;

public class ESUtil {

    /**
     * 获取ES客户端
     * @return
     */
    public static RestHighLevelClient getClient() {
        RestClientBuilder builder = RestClient.builder(
                new HttpHost("192.168.118.130", 9200, "http")
        );
        builder.setRequestConfigCallback(requestConfigBuilder ->
                requestConfigBuilder
                        .setConnectTimeout(30_000)     // 连接建立超时
                        .setSocketTimeout(60_000)      // 数据传输超时
                        .setConnectionRequestTimeout(30_000) // 连接池获取连接超时
        );
        return new RestHighLevelClient(builder);
    }

}
